<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Kowcore
 * @copyright  Copyright KEENONWEB LLC
 * @license    http://www.keenonweb.com/
 * @version    $Id: Controller.php 2011-03-09 08:45:41Z idris $
 * @author     Idris
 */

/**
 * @category   Application_Extensions
 * @package    Kowcore
 * @copyright  Copyright KEENONWEB LLC
 * @license    http://www.keenonweb.com/
 */

class Kowcore_Widget_NoteController extends Engine_Content_Widget_Abstract
{
  public function indexAction()
  {
    if (!Engine_Api::_()->core()->hasSubject()) {
      return $this->setNoRender();
    }
    
    $this->view->subject = $subject = Engine_Api::_()->core()->getSubject();
    $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
    $this->view->defaultText = $defaultText = $this->view->translate('Write something about %s', $subject->getTitle());

    $this->view->note = $note = Engine_Api::_()->kowcore()->getNote($subject);
    $this->view->noteText = $noteText = $note->note ? $note->note : $defaultText;

    $this->view->allowedEdit = $allowedEdit = $subject->isOwner($viewer); // $subject->authorization()->isAllowed($viewer, 'edit');
    if (!$note && !$allowedEdit) {
      $this->setNoRender();
      return ;
    }
  }
}